<?php
/**
 * 用户管理
 *
 * @copyright   Copyright 2011, Richie
 * @author      Richie <richbossman@163.com>
 * @package     SMS
 * @link        http://www.letphp.com
 * 
 * $Id: UserAction.class.php 76 2011-04-07 14:09:03Z 442767452@qq.com $
 */
class UserAction extends SMSAction {
	
	function _before_index(){
		
	}
	
	function _button_user_add(){
		return array('index');
	}
	
	function _button_user_edit(){
		return array('index', 'add');
	}
	
	function _button_user_index(){
		return array('add');
	}
	
	function _before_add(){
		$this->assign('dept', A('Dept', 'data')->dept_list());
	}
	
	function _before_edit(){
		$this->assign('dept', A('Dept', 'data')->dept_list());
	}
	
	//列表json
	function lst(){
		$result = array();
		$where = "";
		$this->datagrid['sort'] = isset($_REQUEST['sort']) ? 'n.'.trim($_REQUEST['sort']) : 'n.sort';
		$result['total'] = M()->table(C('DB_PREFIX').'user AS n')->where($where)->count();
		$result['rows'] = M()->table(C('DB_PREFIX').'user AS n')->field('n.id, n.username, n.status, n.last_login_time, n.sort, n.add_time, n.remark')
				->page($this->datagrid['page'])
				->limit($this->datagrid['rows'])
				->order($this->datagrid['sort'].' '.$this->datagrid['order'])
				->where($where)
				->findAll();
		foreach ($result['rows'] as $key=>$row){
			$result['rows'][$key]['add_time'] = date('Y-m-d H:i', $row['add_time']);
			$result['rows'][$key]['last_login_time'] = empty($row['last_login_time']) ? '--' : date('Y-m-d H:i', $row['last_login_time']);
			$result['rows'][$key]['status'] = (!empty($row['status'])) ? '启用' : '禁用';
		}
		$this->ajaxReturn('', $result);
	}
}
?>